
const SERVER_BASE_URL='http://localhost:8080';

axios.defaults.baseURL=SERVER_BASE_URL;
axios.defaults.timeout=5000;
axios.defaults.withCredentials=true;
//添加响应拦截器
axios.interceptors.response.use(function (response) {
    let r=null;
    //对响应数据做点什么
    if(response.status==200){
        let ajaxResult=response.data;
        if(ajaxResult.code==0){
            r=ajaxResult.data;
        }else{
            ElementPlus.ElMessage({
                type:'error',
                message:ajaxResult.msg
            });
        }
    }
    return r;
}, function (error) {
    //对响应错误做点什么
    return Promise.reject(error);
});

//将传入的角色值转换为角色名称字符串
function convert2RoleName(role) {
    let name = "";
    switch (role) {
        case 0:
            name = "系统管理员";
            break;
        case 1:
            name = "售票员";
            break;
        case 2:
            name = "站务员";
            break;
        case 3:
            name = "司机";
            break;
        case 4:
            name = "行包员";
            break;
    }
    return name;
}

//将传入的日期对象转换为"yyyy-MM-dd"格式的字符串
function formatDate(d) {
    let result = null;
    if (d) {
        let y = d.getFullYear();
        let m = d.getMonth() + 1;
        let d1 = d.getDate();
        result = y + "-" + ((m < 10) ? ("0" + m) : m) + "-" + ((d1 < 10) ? ("0" + d1) : d1);
    }
    return result;
}

//将传入的long值转换为Date对象
function parse2Date(value) {
    let result = null;
    if (value) {
        result = new Date(value);
    }
    return result;
}